<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .btn{
            display: inline-block;
            width: 100px;
            height: 50px;
            border: 1px solid;
            line-height: 50px;
            text-align: center;
            cursor: pointer;
        }
        .btn.active{
            background-color: pink;
        }
        .content{
            border: 5px dashed red;
            width: 400px;
            height: 400px;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="btn" :class="page=='home'?'active':''" @click="page='home'">首页</div>
        <div class="btn" :class="page=='news'?'active':''" @click="page='news'">新闻</div>
        <div class="btn" :class="page=='yule'?'active':''" @click="page='yule'">娱乐</div>
        <div class="content">
            <keep-alive>
                <component :is="page"></component>
            </keep-alive>
        </div>
    </div>
    <script src="../js/vue.js"></script>
    <script>
        let home = {
            template: `<h1>HOME</h1>`,   
            activated() {
                console.log('home被激活')
            },
        }
        let news = {
                template: `<h1>news</h1>`,
                activated() {
                    console.log('news被激活')
                },
            }
        let yule = {
                template: `<h1>yule</h1>`,
                activated() {
                    console.log('yule被激活')
                },
            }
        let vm = new Vue({
            el: '#app',
            data: {
                page:'home'
            },
            methods: {

            },
            components: {
                home,news,yule
            }
        })
    </script>
</body>
</html>